import { Camera, Scene, WebGLRenderer } from 'three'

const renderer = new WebGLRenderer({
  alpha: true
})
renderer.setClearColor(0x000000, 0.0)

export function render (scene: Scene, camera: Camera, canvas: HTMLCanvasElement) {
  const width = canvas.width
  const height = canvas.height
  const ctx = canvas.getContext('2d')!

  renderer.setSize(width, height, true)
  renderer.render(scene, camera)
  ctx.clearRect(0,0,width,height)
  ctx.drawImage(renderer.domElement, 0, 0)
  return canvas
}

export function render256 (scene: Scene, camera: Camera) {
  renderer.setSize(256, 256, true)
  renderer.render(scene, camera)
  return renderer.domElement.toDataURL()
}
